# *-*- coding:utf-8 -*-
# @Author  : Eliza
# @Time    : 2021/7/18 0:12
# @Software : RubyMine

# hash 字典
# 定义
hash01 = { :a => 1, :b => "as" }
puts hash01
mvp = {
  "A" => 1,
  "B" => 2,
  "C" => 3,
}
puts mvp
puts mvp["A"]
puts "------------"

# JSON
# index: 紧紧贴着
player = {
  p1: 1,
  p2: 2,
  p3: 3
}
puts player
puts player[:p2]
puts "----------"
puts mvp.object_id
puts mvp["A"].object_id
puts mvp["B"].object_id
puts mvp["C"].object_id
puts "-----hash.new -------"
puts Hash.new
h = Hash.new(3) #默认值3
puts h[0], h[1], h[2] #3
puts "-----hash.new -------"
h = { a: 1, b: 2 }
puts h.assoc(:b) #返回对应的健值对
puts h.rassoc(1) #返回对应的值健对
puts "----- -------"
puts h.delete(:a) #删除返回对应的值
puts "----- -------"
puts h.merge(hash01).merge(player) #混合

puts "-----遍历hash----------"
player.each { |key, value| p [key, value] }

